package com.example.myinitializrspringbootapp.config;


import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 使用内置的Jetty Web容器
 * 1.配置Jetty Web容器
 * 2.从POM中排除默认的Tomcat容器
 */
@Configuration
public class JettyWebServerFactoryConfig {
    /**
     * 方法一
     * 配置当前的Web容器为Jetty
     */
    /*@Bean
    public JettyServletWebServerFactory webServerFactory(){
        JettyServletWebServerFactory factory=new JettyServletWebServerFactory();
        factory.setPort(8084);
        return factory;
    }*/
    /**
     * 方法二
     * 配置WebServerFactoryCustomizer,重写customizer()方法,强转相应的JettyServletWebServerFactory
     */
/*    @Bean
    public WebServerFactoryCustomizer webServerFactoryCustomizer(){
        WebServerFactoryCustomizer customizer=new WebServerFactoryCustomizer() {
            @Override
            public void customize(WebServerFactory factory) {
                JettyServletWebServerFactory factory1= (JettyServletWebServerFactory) factory;
                factory1.setPort(8080);
            }
        };
        return customizer;
    }*/
}
